package org.lyh.base.controller;

import io.swagger.annotations.Api;
import org.lyh.base.service.IVerifyCodeservice;
import org.lyh.base.util.Result;
import org.lyh.user.domain.User;
import org.lyh.user.pojo.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/common/verifycode")
@Api(tags = "验证码")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeservice verifyCodeservice;

    @GetMapping("/imageCode/{ImageCodeKey}")
    public Result getImageCode(@PathVariable("ImageCodeKey") String ImageCodeKey) throws Exception{
        try {
            String base64ImageCode=verifyCodeservice.getImageCode(ImageCodeKey);
            return Result.success(base64ImageCode);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取图形验证码失败，请刷新！");
        }
    }
    @PostMapping("/sendSmsCode")
    public Result sendSmsCode(@RequestBody UserDTO userDTO) throws Exception{
        try {
            verifyCodeservice.sendSmsCode(userDTO);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取手机验证码失败，请稍后重试！");
        }
    }
    @PostMapping("/smsbind")
    public Result smsbind (@RequestBody UserDTO userDTO) throws Exception{
        try {
            verifyCodeservice.smsbind(userDTO);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取手机验证码失败，请稍后重试！");
        }
    }
}
